// axios基础的封装
import axios from 'axios'
import {ElMessage} from "element-plus";

const httpInstance = axios.create({
    baseURL: 'http://localhost:8080/',
    // baseURL: 'http://pcapi-xiaotuxian-front-devtest.itheima.net',
    timeout: 5000
})

// axios请求拦截器
httpInstance.interceptors.request.use(config => {
    //在发送之前做什么
    return config
}, e => {
    //对请求错误做什么
    ElMessage.error("http请求错误：" + e.message);
    return Promise.reject(e)
})

// axios响应式拦截器
httpInstance.interceptors.response.use(res => {
    //对请求后的响应数据做什么
    //res里面包含了config等信息,res.data才是后端返回的对象
    return res.data
}, e => {
    ElMessage.error("服务器错误："+ e.message);
    return Promise.reject(e)
});


export default httpInstance